define(['jquery'], () => {
    class Header {
        constructor() {
            this.init().then(() => {
                this.calcCartCount()
            })
            let cart = localStorage.getItem('cart')
                    if (cart) {
                        cart = JSON.parse(cart)
                        const totalCount = cart.reduce((count, shop) => count + shop.count, 0)
                        $('#num').html(totalCount)
                    }

        }
        init() {
            return new Promise(resolve => {
                $('header').load('/html/modules/header.html')
            })
        }
        calcCartCount() {
            let cart = localStorage.getItem('cart')
            if (cart) {
                cart = JSON.parse(cart)
                const totalCount = cart.reduce((count, shop) => count + shop.count, 0)
                $('#num').html(totalCount)
            }
        }
    }
    return new Header()
})